﻿using DG.Tweening;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

public class PropUI : MonoBehaviour
{
    [SerializeField] Image image;
    [SerializeField] TextMeshProUGUI introductionText;
    [SerializeField] TextMeshProUGUI costText;
    [SerializeField] Button buyBT;

    public PropData Data;

    private void Start()
    {
        buyBT.onClick.AddListener(OnBuyBTClick);
    }

    public void Init(PropData propData)
    {
        Data = propData;
        image.sprite=Data.Image;
        introductionText.text = Data.Introduction;
        costText.text= Data.Cost.ToString();
    }

    void OnBuyBTClick()
    {
        if(!PropManager.Instance.TryBuyProp(this))
        {
            buyBT.image.DOColor(Color.red,0.5f).OnComplete(()=>buyBT.image.DOColor(Color.white,0.5f));
            buyBT.transform.DOShakePosition(0.5f,10,20);
        }
    }
}
